package com.qianfeng.handlers;

import com.qianfeng.dto.Message;
import com.qianfeng.dto.Result;
import com.qianfeng.exceptions.CommonException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class CommonHandler {


    @ResponseBody
    @ExceptionHandler(value = {CommonException.class})
    public Result CommonHandlers(CommonException e) {
        e.printStackTrace();
        Message message = new Message();
        message.setMsg(e.getMsg());
        message.setCode(e.getCode());
//        System.out.println(message);
        Result result = new Result();
        result.setMessage(message);
        return result;
    }
}


